package com.example.hellofxend.program;


import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.example.hellofxend.data.IPData;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class HelloController {
    @FXML
    private Label myText;
    @FXML
    private TextField ipTxt;

    @FXML
    protected void onHelloButtonClick() {
        //起到一个Loading的效果
        myText.setText("Loading……");
        String ipVal = ipTxt.getText();
        //异步机制
        Platform.runLater(() -> {
            String url = "https://widget.cifuwu.com/idcard/" + ipVal;
            String result = HttpUtil.get(url);
            IPData ipData = JSONUtil.toBean(result, IPData.class);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String outMsg = "结果:" + ipData.getMessage()+"\n";
            outMsg+="code:" + ipData.getCode()+"\n";
            outMsg+="居住地代码:" + ipData.getData().getAreaInfo().getCode()+"\n";
            outMsg+="年龄:" + ipData.getData().getBorn().getAge()+"\n";
            outMsg+="总阴历:" + ipData.getData().getBorn().getLunar().getChinese_birthday()+"\n";
            outMsg+="阴历年份:" + ipData.getData().getBorn().getLunar().getChinese_year()+"\n";
            outMsg+="阴历月份:" + ipData.getData().getBorn().getLunar().getChinese_month()+"\n";
            outMsg+="阴历日:" + ipData.getData().getBorn().getLunar().getChinese_date()+"\n";
            outMsg+="总阳历:" + ipData.getData().getBorn().getSolar().getBirthday()+"\n";
            outMsg+="阳历年份:" + ipData.getData().getBorn().getSolar().getYear()+"\n";
            outMsg+="阳历月份:" + ipData.getData().getBorn().getSolar().getMonth()+"\n";
            outMsg+="阳历日:" + ipData.getData().getBorn().getSolar().getDate()+"\n";
            outMsg+="属性:" + ipData.getData().getBorn().getLunar().getChinese_zodiac()+"\n";
            outMsg+="星座:" + ipData.getData().getBorn().getSolar().getZodiac()+"\n";
            outMsg+="时间戳:" + ipData.getData().getBorn().getTimestamp()+"\n";
            outMsg+="性别英文:" + ipData.getData().getGender().getEn()+"\n";
            outMsg+="性别:" + ipData.getData().getGender().getCn()+"\n";
            myText.setText(outMsg);
        });

    }
}